//
//  TMTradeDetailController.m
//  国学商家管理
//
//  Created by Tao Li on 2018/7/2.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TMTradeDetailController.h"
#import "TMListView.h"
#import "TMUserViewModel.h"
#import "TMCourseDetailModel.h"
@interface TMTradeDetailController ()
@property (nonatomic, strong) TMUserViewModel *viewModel;
@property (weak, nonatomic) IBOutlet UIImageView *headImageV;
@property (weak, nonatomic) IBOutlet UILabel *courseLabel;
@property (weak, nonatomic) IBOutlet UILabel *totalTime;
@property (weak, nonatomic) IBOutlet UILabel *liftTime;
@property (weak, nonatomic) IBOutlet UILabel *openTime;
@property (weak, nonatomic) IBOutlet UIView *haveInView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftConst;
@property (weak, nonatomic) IBOutlet UIView *listView;
@property (nonatomic, strong) TMListView *listView1;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (nonatomic, strong) TMCourseDetailModel *detailModel;
@property (weak, nonatomic) IBOutlet UIImageView *codeImageView;
@property (weak, nonatomic) IBOutlet UITableViewCell *recordsCell;
@property (nonatomic, strong) NSArray *list;
@end

@implementation TMTradeDetailController
- (NSArray *)list{
    if (!_list) {
        _list = [NSArray array];
    }
    return _list;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"课程详细";
   // [self displayHaveInView];
    _listView1 =  [[NSBundle mainBundle] loadNibNamed:@"TMListView" owner:nil options:nil][0];
    _listView1.isCourse = YES;
    _listView1.isStarsShow = NO;
    _listView1.frame = self.listView.bounds;
    [self.listView addSubview:_listView1];
    self.recordsCell.hidden = YES;
    self.tableView.tableFooterView = [UIView new];
    self.viewModel = [[TMUserViewModel alloc]init];
    if (self.isorder ==YES) {
        [self.viewModel getOrderCourseDetailWith:self.cid And:self.order_id Success:^(id responseObject) {
            self.detailModel = responseObject[1];
            _list = responseObject[0];
            [self displayTab:self.detailModel];
            self.listView1.list = responseObject[0];
        } failed:^(NSString *error) {
            
        }];
    }else{
    [self.viewModel getMyCourseDetailWith:self.cid And:self.order_id Success:^(id responseObject) {
        self.detailModel = responseObject[1];
        _list = responseObject[0];
        [self displayTab:self.detailModel];
        self.listView1.list = responseObject[0];
        [self.tableView reloadData];
    } failed:^(NSString *error) {
        
    }];
    }
    
}

- (void)displayTab:(TMCourseDetailModel *)models{
    self.headImageV.contentMode = UIViewContentModeScaleAspectFill;
    self.headImageV.clipsToBounds = YES;
    [self.headImageV sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithBaseUrl:models.pic[0]]] placeholderImage:kPlaceholder];
    //self.courseLabel.text = models.name;
    self.courseLabel.text = [NSString stringWithFormat:@"课程名：%@", models.name];
    //电话：187******347
    self.totalTime.text = [NSString stringWithFormat:@"总课长：%ld", models.num];
    self.liftTime.text = [NSString stringWithFormat:@"剩余课长：%ld", models.num];
    self.openTime.text = [NSString stringWithFormat:@"开课时间：%@",
                          [SPToolSet stringFromDateString:models.s_time]];
    [self.codeImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithBaseUrl:models.url]] placeholderImage:kPlaceholder];
    if ([models.addr isKindOfClass:[NSNull class]]) {
        models.addr = @"";
    }
    self.addressLabel.text = [NSString stringWithFormat:@"地址：%@", models.addr];
////    self.cid = models.cid;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 151;
    }
    if (indexPath.row == 6) {
        return 200;
    }
    if (indexPath.row == 7) {
        return 0;
    }
    return 49;
}


- (void)displayHaveInView{
    _haveInView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
    float itemW = _haveInView.bounds.size.width/5;
    if (kWindowW == 320) {
        self.leftConst.constant = 73;
        itemW = 40;
    }
    if(kWindowW ==375){
        self.leftConst.constant = 84;
        //itemW = 44;
    }
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 8; j++) {
            UILabel *label = [[UILabel alloc]init];
            if (kWindowW == 320) {
                if (i == 0) {
                    label.frame = CGRectMake(5 +itemW*i, 0 +15* j , itemW-5, 12);
                }else{
                    label.frame = CGRectMake(2 +itemW*i, 0 +15* j , itemW-5, 12);
                }
            }else if(kWindowW == 375){
                if (i == 0) {
                    label.frame = CGRectMake(8 +(itemW-2)*i, 0 +15* j , itemW-5, 12);
                }else{
                    label.frame = CGRectMake(2 +(itemW-2)*i, 0 +15* j , itemW-5, 12);
                }
            }else{
                label.frame = CGRectMake(5 +itemW*i, 0 +15* j , itemW-5, 12);
            }
            label.text = @"已上课";
            label.font = [UIFont systemFontOfSize:12];
            if (kWindowW == 320) {
                 label.font = [UIFont systemFontOfSize:10];
            }
            label.textColor = [UIColor hx_colorWithHexRGBAString:@"#05B48D"];
            [_haveInView addSubview:label];
        }
    }
}


@end
